package com.mszlu.news.admin.controller;

import com.mszlu.news.admin.model.params.ArticleParam;
import com.mszlu.news.admin.service.ArticleService;
import com.mszlu.news.admin.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "文章接口")
@RestController
@RequestMapping("article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @ApiOperation(value = "根据条件查询")
    @PostMapping("select")
    public Result selectArticle(@RequestBody ArticleParam articleParam){
        return articleService.selectArticle(articleParam);
    }

    @ApiOperation(value = "热门文章")
    @PostMapping("hot")
    public Result hotArticle(){
        int limit = 5;
        return articleService.hotArticle(limit);
    }

    @ApiOperation(value = "添加文章")
    @PostMapping("add")
    public Result addArticle(@RequestBody ArticleParam articleParam){
        return articleService.addArticle(articleParam);
    }

    @ApiOperation(value = "更新文章")
    @PostMapping("update")
    public Result updateArticle(@RequestBody ArticleParam articleParam){
        return articleService.updateArticle(articleParam);
    }

    @ApiOperation(value = "通过id删除文章及其关联的表数据")
    @PostMapping("delete/{id}")
    public Result deleteArticleById(@PathVariable("id") Long articleId){
        return articleService.deleteArticleById(articleId);
    }

    @ApiOperation(value = "置顶文章")
    @PostMapping("top")
    public Result topArticle(@RequestBody ArticleParam articleParam){
        return articleService.topArticle(articleParam);
    }

    @ApiOperation(value = "统计各类资讯观看总数")
    @GetMapping("view")
    public Result viewArticle(){
        return articleService.viewArticle();
    }
}
